package com.pilipili.zeus.eduService.controller;


import com.pilipili.commonutils.Result;
import com.pilipili.zeus.eduService.entity.subject.SubjectNode;
import com.pilipili.zeus.eduService.service.EduSubjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 番剧科目 前端控制器
 *
 * @author Unlimited_Blade_Works
 * @since 2021-05-25
 */
@RestController
@RequestMapping("/eduService/subject")
public class EduSubjectController {
    @Autowired
    private EduSubjectService subjectService;

    @ApiOperation(value = "读取SubjectExcel中的表格,写入数据库")
    @PostMapping("addSubjects")
    public Result addSubject(MultipartFile file){
        subjectService.saveSubject(file,subjectService);
        return Result.ok();
    }
    @ApiOperation(value = "读取树形分类列表")
    @GetMapping("getSubjects")
    public Result getSubjects(){
        List<SubjectNode> list=subjectService.getSubjectTree();
        return Result.ok().data("list",list);
    }
    @ApiOperation(value = "给番剧分配标签,多对多数据库关联表范例")
    @DeleteMapping("sortCourse")
    public Result sortCourse(String courseId, String[] subjectId){
        subjectService.saveCourseSubjectRelationShip(courseId,subjectId);
        return  Result.ok();
    }
}

